package crossbreed.tests.presenters;

import java.awt.Color;
import java.util.ArrayList;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.Document;
import org.junit.Before;
import org.junit.Test;
import crossbreed.models.ComparisonModel.ComparisonLine;
import crossbreed.models.ComparisonModel.ComparisonModelListener;
import crossbreed.models.ComparisonModel.IComparisonModel;
import crossbreed.models.ComparisonModel.LineType;
import crossbreed.presenters.LeftFilePresenter;
import crossbreed.views.IFileView;

public class LeftFilePresenterTests
{
	private class MockComparisonModel implements IComparisonModel
	{
		public ArrayList<ComparisonLine> leftLines;
		
		public MockComparisonModel()
		{
			leftLines = new ArrayList<ComparisonLine>();
		}

		@Override
		public void createDiff()
		{
		}
		
		@Override
		public String getLeftFilePath()
		{
			return null;
		}

		@Override
		public ArrayList<ComparisonLine> getLeftLines()
		{
			return leftLines;
		}

		@Override
		public String getRightFilePath()
		{
			return null;
		}
		
		@Override
		public void setLeftFilePath(String leftFilePath)
		{
		}

		@Override
		public void setRightFilePath(String rightFilePath)
		{
		}

		@Override
		public void addListener(ComparisonModelListener listener)
		{
		}

		@Override
		public ArrayList<ComparisonLine> getRightLines()
		{
			return null;
		}
	}
	
	private class MockFileView implements IFileView
	{
		public DefaultStyledDocument document;
		
		@Override
		public void displayDocument(Document doc)
		{
			document = (DefaultStyledDocument) doc;
		}

		@Override
		public void scrollToPosition(int position)
		{
		}

		@Override
		public void addHighlight(int indexStart, Color color)
		{
		}

		@Override
		public void updateHighlights(int offset, int length)
		{
		}
	}
	
	private MockFileView mockView;
	private MockComparisonModel mockModel;
	private LeftFilePresenter leftPresenter;
	
	@Before
	public void initialize()
	{
		mockView = new MockFileView();
		mockModel = new MockComparisonModel();
		leftPresenter = new LeftFilePresenter(mockModel);
		leftPresenter.setView(mockView);
	}
	
	@Test
	public void shouldReturnOneSwapOneInsertAndSameText()
	{
		mockModel.leftLines.add(new ComparisonLine("A", LineType.SWAP));
		mockModel.leftLines.add(new ComparisonLine("B", LineType.INSERT));
		mockModel.leftLines.add(new ComparisonLine("C", LineType.SAME));		
		leftPresenter.diffCreationComplete();
	}
}
